#include "dac7811.h"


uint8 DA_ON[4] ={0,0,0,1};



//Enable the DAC7811's pins

void dacInit()

{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
    SCLK_OUT;
    SDIN_OUT ;
    SYNC_OUT ;

    SYNC_DOWN;
    SDIN_UP;
    SCLK_DOWN;
}



//Write the data to DAC7811

void dacWrite(uint16_t daData)

{
    uint8_t i;
     SYNC_DOWN;
     SCLK_UP;
    for( i=0;i<4;i++)    {
        SCLK_UP;
        if(DA_ON[i])
        {
            SDIN_UP;
        }
        else
        {
            SDIN_DOWN;
        }
        SCLK_DOWN;
    }
    for(i=0;i<12;i++)    {
        SCLK_UP;
        if(daData&0x800)
        {
            SDIN_UP;
        }
        else
        {
           SDIN_DOWN;
        }
        SCLK_DOWN;
        daData<<=1;
    }
        SDIN_UP;
        SYNC_UP;
        SCLK_DOWN;
        for( i=0;i<4000;i++);
}


